package ar.pmt.gwt.client.recurso.view.smart;
/* 
 * SmartGWT (GWT for SmartClient) 
 * Copyright 2008 and beyond, Isomorphic Software, Inc. 
 * 
 * SmartGWT is free software; you can redistribute it and/or modify it 
 * under the terms of the GNU Lesser General Public License version 3 
 * as published by the Free Software Foundation.  SmartGWT is also 
 * available under typical commercial license terms - see 
 * http://smartclient.com/license 
 * 
 * This software is distributed in the hope that it will be useful, 
 * but WITHOUT ANY WARRANTY; without even the implied warranty of 
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU 
 * Lesser General Public License for more details. 
 */  
  
import ar.pmt.gwt.client.core.MethodRequest;
import ar.pmt.gwt.client.core.UtilGwt;
import ar.pmt.vista.beans.AsignacionBean;
import ar.pmt.vista.beans.RecursoBean;
import ar.pmt.vista.beans.StringBean;

import com.google.gwt.json.client.JSONArray;  
import com.google.gwt.json.client.JSONString;  
import com.google.gwt.user.client.ui.Composite;
import com.smartgwt.client.data.*;  
import com.smartgwt.client.data.fields.DataSourcePasswordField;  
import com.smartgwt.client.data.fields.DataSourceTextField;  
import com.smartgwt.client.rpc.RPCResponse;  
import com.smartgwt.client.types.DSDataFormat;  
import com.smartgwt.client.widgets.Canvas;  
import com.smartgwt.client.widgets.IButton;  
import com.smartgwt.client.widgets.events.ClickHandler;  
import com.smartgwt.client.widgets.form.DynamicForm;  
import com.smartgwt.client.widgets.form.fields.HeaderItem;  
import com.smartgwt.client.widgets.form.fields.HiddenItem;
import com.smartgwt.client.widgets.form.fields.PasswordItem;  
import com.smartgwt.client.widgets.grid.ListGrid;
import com.smartgwt.client.widgets.layout.VLayout;  

  
public class FormServerJsonValidationSample extends Composite  {  
  
    public FormServerJsonValidationSample() {  
  
        
        
        final MethodRequest methodRequest = new MethodRequest("ar.pmt.vista.manager.RecursoManager","obtenerRecurso");
    	methodRequest.agregarClasesArgumento(StringBean.class); 
    	methodRequest.agregarAtributos(StringBean.getValorID(), "74009");
    	
    	 DataSource dataSource = new DataSource();  
         dataSource.setDataFormat(DSDataFormat.JSON); 
        dataSource.setDataURL("//localhost:8031/PMT-GWT/pmtJson"+methodRequest.toRequestUrl());  
        DataSourceTextField userNameField = new DataSourceTextField(RecursoBean.getUnicoIdID(), "Username", 50, true);  
        DataSourceTextField firstNameField = new DataSourceTextField(RecursoBean.getNombreID(), "First Name", 50, true);  
        DataSourceTextField lastNameField = new DataSourceTextField(RecursoBean.getApellidoID(), "Last Name", 50, true);  
        DataSourceTextField emailField = new DataSourceTextField(RecursoBean.getEmailID(), "Email", 100, true); 
        
      
  
        DataSourcePasswordField passwordField = new DataSourcePasswordField("password", "Password", 20, true);  
  
        dataSource.setFields(userNameField, firstNameField, lastNameField, emailField, passwordField);  
       
        
         ListGrid grid = new ListGrid();  
                 grid.setDataSource(dataSource);  
                 grid.setWidth("100%");  
                 grid.setHeight(100);  
               //  grid.setAutoFetchData(true);  
                 grid.draw();  
  
        final DynamicForm form = new DynamicForm();  
       form.addChild(grid); 
        //form.setAutoFetchData(true);
  
        HeaderItem header = new HeaderItem();  
        header.setDefaultValue("Registration Form");  
  
        PasswordItem passwordItem = new PasswordItem();
        passwordItem.setName("password");  
        
        HiddenItem hiddenItem = new HiddenItem();
        hiddenItem.setName("_clases");
        hiddenItem.setValue(RecursoBean.class.toString());
        
        HiddenItem hiddenItem2 = new HiddenItem();
        hiddenItem2.setName("_clases");
        hiddenItem2.setValue("following");
        
      
  
     
        IButton saveButton = new IButton("Save");  
        saveButton.addClickHandler(new ClickHandler() {  
            public void onClick(com.smartgwt.client.widgets.events.ClickEvent event) {
      
            	DSRequest ds = new DSRequest();
            	ds.setActionURL(methodRequest.toRequestUrl());
            	
            	
            	form.setAction("//localhost:8031/PMT-GWT/pmtJson"+methodRequest.toRequestUrl());
                form.submit();
            }  
        });  
  
        form.setFields(header, passwordItem, hiddenItem2, hiddenItem);  
  
        form.setValue("userName", "bsmith");  
        form.setValue("firstName", "Bob");  
        form.setValue("lastName", "Smith");  
        form.setValue("email", "bob@.com");  
        form.setValue("password", "sekrit");  
  
        VLayout layout = new VLayout(10);  
        layout.addMember(form);  
        layout.addMember(saveButton);  
        initWidget(layout);
    }  
  
}   